package sq.repository;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import sq.dao.Address;

import javax.transaction.Transactional;
import java.util.Date;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: sunquan
 * @Date: 2018/3/28
 * @Time: 22:39
 */
public interface AddressRepository  extends JpaRepository<Address, Integer> {
    //更新菜品
    @Transactional
    @Modifying
    @Query(value = " UPDATE Address a SET a.userId = :newUserId," +
            "a.phone = :newPhone,a.username=:newUsername," +
            "a.schoolAddress=:newSchoolAddress,a.addressDetail=:newAddressDetail where a.userId=:newUserId")
    Integer updateAddressByAddressId(@Param("newUserId") Integer newUserId,
                               @Param("newPhone") String newPhone,
                               @Param("newUsername") String newUsername,
                               @Param("newSchoolAddress") Integer newSchoolAddress,
                               @Param("newAddressDetail") String newAddressDetail);

    Address findAddressByUserId(Integer userId);
}
